/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file           : mf_i2c.h
 * @brief          : Header for mf_i2c.c file.
 *                   This file contains the common defines of the application.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) [2021] [Fudan Microelectronics]
 * THIS SOFTWARE is licensed under Mulan PSL v2.
 * can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 *
 ******************************************************************************
 */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MF_I2C_H
#define __MF_I2C_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mf_config.h"

#if defined(USE_FULL_ASSERT)
#include "fm33_assert.h"
#endif /* USE_FULL_ASSERT */

    /* Private includes ----------------------------------------------------------*/
    /* USER CODE BEGIN Includes */

    /* USER CODE END Includes */

    /* Exported types ------------------------------------------------------------*/
    /* USER CODE BEGIN ET */
    typedef enum
    {
        I2C_START_DS,
        I2C_RESTART_DS,
        I2C_STOP_DS
    } MF_I2C_BIT_DS;

    typedef enum
    {
        I2C_REG_BYTE_ADDR,
        I2C_REG_OVER_ADDR
    } MF_I2C_REG_ADDR_LEN;

    typedef enum
    {
        I2C_MASTER_WRITE,
        I2C_MASTER_READ
    } MF_I2C_OPTION;

#define MF_I2C_BASE (I2C)         /* i2c base_addr */
#define MF_I2C_TIMEOUT (0x1FFFFU) /* timeout max */
    /* USER CODE END ET */

    /* Exported constants --------------------------------------------------------*/
    /* USER CODE BEGIN EC */

    /* USER CODE END EC */

    /* Exported macro ------------------------------------------------------------*/
    /* USER CODE BEGIN EM */

    /* USER CODE END EM */

    /* Exported functions prototypes ---------------------------------------------*/

    /* USER CODE BEGIN EFP */

    void mf_i2c_master_init(I2C_Type *I2Cx, GPIO_Type *i2c_clk_gpiox, uint32_t i2c_clk_pin, GPIO_Type *i2c_sda_gpiox, uint32_t i2c_sda_pin, uint32_t baud_rate);
    FL_ErrorStatus mf_i2c_master_write_to_device(uint8_t dev_addr, uint16_t reg_addr, MF_I2C_REG_ADDR_LEN reg_addr_len, uint8_t *pdata, uint8_t data_len);
    FL_ErrorStatus mf_i2c_master_read_from_device(uint8_t dev_addr, uint16_t reg_addr, MF_I2C_REG_ADDR_LEN reg_addr_len, uint8_t *pdata, uint8_t data_len);
    /* USER CODE END EFP */

    /* Private defines -----------------------------------------------------------*/

    /* USER CODE BEGIN Private defines */

    /* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MF_I2C_H */

/************************ (C) COPYRIGHT FMSH *****END OF FILE****/
